package com.neusoft.crm.service.impl;

import com.neusoft.crm.entity.CommonResult;
import com.neusoft.crm.entity.Dict;
import com.neusoft.crm.mapper.DictMapper;
import com.neusoft.crm.service.IDictService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 东软集团
 * @since 2023-03-29
 */
@Service
public class DictServiceImpl extends ServiceImpl<DictMapper, Dict> implements IDictService {
    @Autowired
    DictMapper dictMapper;

    @Override
    public CommonResult findall() {
        List<Dict> lds =  dictMapper.selectList(null);
        CommonResult result =  new CommonResult(lds);
        if (lds ==null || lds.size()==0){
            result.setNotFound();
        }
        return result;
    }

    @Override
    public CommonResult addDict(Dict dict) {
        dict.setDictno(null);
        int  i =  dictMapper.insert(dict);
        CommonResult result =  new CommonResult( dict.getDictno() );

        if (i<1){
            result.setNotModified();
        }
        return result;
    }

    @Override
    public CommonResult modDict(Dict dict) {
        int  i =  dictMapper.updateById(dict);
        CommonResult result =  new CommonResult(i);
        if (i <1){
            result.setNotModified();
        }
        return result;
    }


}
